package com.example.qxfw.dzzh.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.yj.DzWarning;
import com.example.qxfw.dzzh.service.DzzhYjcxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

@Api(tags = "地质灾害-预警查询")
@RestController
@CrossOrigin
@RequestMapping("/dzzh/yjcx")
public class DzzhYjcxController {

    @Autowired
    private DzzhYjcxService dzzhYjcxService;

    @ApiOperation("查询产品列表")
    @GetMapping("/getProductList")
    public SysResult getProductList(String start,String end,Integer state) throws ParseException {
        List<DzWarning> dzWaringList = dzzhYjcxService.getDzWaringList(start, end, state);
        return SysResult.success(dzWaringList);
    }

    @ApiOperation("更新产品状态")
    @GetMapping("/updateState")
    public SysResult updateState(Integer docId,Integer state){
        DzWarning dzWarning = dzzhYjcxService.updateState(docId, state);
        return SysResult.success(dzWarning);
    }

    @ApiOperation("获取产品id")
    @GetMapping("/getProductId")
    public SysResult getProductId(Integer docId,String docPath){
        Integer productId = dzzhYjcxService.getProductId(docId, docPath);
        return SysResult.success(productId);
    }

    @ApiOperation("删除产品")
    @GetMapping("/deleteProduct")
    public SysResult deleteProduct(Integer docId){
        DzWarning dzWarning = dzzhYjcxService.deleteProduct(docId);
        return SysResult.success(dzWarning);
    }
}
